<?php
/**
 * Created by: i@fedax.cn
 * Date: 2018/7/16 22:39
 */

namespace app\admin\controller;

use app\admin\model\AliPay as AliPayModel;
class AliPay extends Index
{
    /**
     * @return \think\response\View
     */
    public function index()
    {
        return view();
    }

    /**
     * @return \think\response\Json
     * @throws \think\exception\DbException
     */
    public function indexData()
    {
        $aliPayModel = new AliPayModel();
        $page_config = array(
            'page' => input('post.offset', 1),
            'list_rows' => input('post.limit', 10),
        );
        $order = input('post.sort', 'id') . " " . input('post.order', 'desc');
        $where = array();//组装搜索语句
        if (input('value')) {
            $where[] = [input('key'), '=', input('value')];
        }
        $data = $aliPayModel->getDataList($page_config, $where, $order);
        return json($data);
    }

    /**
     * 修改
     * @return \think\response\Redirect
     */
    public function edit()
    {

            $aliPayModel = new AliPayModel();

            $newData = array();
            $newData['alipay_card'] = trim(input('alipay_card'));
            $newData['alipay_name'] = trim(input('alipay_name'));
            $newData['phone'] = trim(input('phone'));
            $newData['identity_card'] = trim(input('identity_card'));
            $newData['bank'] = trim(input('bank'));
            $newData['bank_branch'] = trim(input('bank_branch'));
            $newData['bank_number'] = trim(input('bank_number'));

            $res = $aliPayModel->save($newData, ['id' => input('id')]);

            if($res) return ['code'=>100,'msg'=>'修改成功'];

               else  return ['code'=>-100,'msg'=>'修改错误'];

    }
}